package com.ruoyi.system.service.impl;

import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.FamilyMedicine;
import com.ruoyi.system.domain.MedicationRecord;
import com.ruoyi.system.mapper.UseMedicineMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.MedicineMapper;
import com.ruoyi.system.domain.Medicine;
import com.ruoyi.system.service.IMedicineService;

/**
 * 药品信息Service业务层处理
 * 
 * @author shan
 * @date 2025-04-13
 */
@Service
public class MedicineServiceImpl implements IMedicineService
{
    @Autowired
    private MedicineMapper medicineMapper;

    @Autowired
    private UseMedicineMapper useMedicineMapper;

    /**
     * 查询药品信息
     * 
     * @param id 药品信息主键
     * @return 药品信息
     */
    @Override
    public Medicine selectMedicineById(Long id)
    {
        return medicineMapper.selectMedicineById(id);
    }

    /**
     * 查询药品信息列表
     * 
     * @param medicine 药品信息
     * @return 药品信息
     */
    @Override
    public List<Medicine> selectMedicineList(Medicine medicine)
    {
        return medicineMapper.selectMedicineList(medicine);
    }

    @Override
    public List<MedicationRecord> listUseMedicine(MedicationRecord medicine) {
        return useMedicineMapper.listUseMedicine(medicine);
    }



    /**
     * 新增药品信息
     * 
     * @param medicine 药品信息
     * @return 结果
     */
    @Override
    public int insertMedicine(Medicine medicine)
    {
        medicine.setCreateTime(new Date());
        medicine.setUpdateTime(new Date());
        return medicineMapper.insertMedicine(medicine);
    }

    /**
     * 修改药品信息
     * 
     * @param medicine 药品信息
     * @return 结果
     */
    @Override
    public int updateMedicine(Medicine medicine)
    {
        medicine.setUpdateTime(new Date());
        return medicineMapper.updateMedicine(medicine);
    }

    /**
     * 批量删除药品信息
     * 
     * @param ids 需要删除的药品信息主键
     * @return 结果
     */
    @Override
    public int deleteMedicineByIds(Long[] ids)
    {
        return medicineMapper.deleteMedicineByIds(ids);
    }

    /**
     * 删除药品信息信息
     * 
     * @param id 药品信息主键
     * @return 结果
     */
    @Override
    public int deleteMedicineById(Long id)
    {
        return medicineMapper.deleteMedicineById(id);
    }

    @Override
    public int insertFamilyMedicine(FamilyMedicine medicine) {
        medicine.setCreateTime(new Date());
        medicine.setUpdateTime(new Date());
        return medicineMapper.insertFamilyMedicine(medicine);
    }


}
